/**
 * Copyright 2010 Adam Ruggles
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package saig.engine.models;

import java.awt.Image;

import saig.engine.models.enums.TileType;


/**
 * A Tile.
 * @author Adam
 * @version $Id$
 *
 * Created on Jun 9, 2010 at 6:05:13 PM
 */
public class Tile {
	/**
     * The current frame to display.
     */
    private int frame;
    /**
     * The id for this tile.
     */
    private Integer id;
    /**
     * The array of images representing the tile.
     */
    private Image[] images;
    /**
     * The tile id for a transition to another block.
     */
    private Integer transitionId;
    /**
     * The tile type.
     */
    private TileType type;
    /**
     * Advances the the tile to the next frame.
     */
    public void advanceFrame() {
    	frame++;
    	if (frame >= images.length) {
    		frame = 0;
    	}
    }
    /**
	 * Returns frame.
	 * @return the frame.
	 */
	public int getFrame() {
		return frame;
	}
	/**
	 * Returns id.
	 * @return the id.
	 */
	public Integer getId() {
		return id;
	}
	/**
     * Returns the image for the current frame.
     * @return The image for the current frame.
     */
    public Image getImage() {
    	return images[frame];
    }
	/**
	 * Returns images.
	 * @return the images.
	 */
	public Image[] getImages() {
		return images;
	}
	/**
	 * Returns transitionId.
	 * @return the transitionId.
	 */
	public Integer getTransitionId() {
		return transitionId;
	}
	/**
	 * Returns type.
	 * @return the type.
	 */
	public TileType getType() {
		return type;
	}
	/**
	 * Sets frame.
	 * @param frame the frame to set.
	 */
	public void setFrame(int frame) {
		this.frame = frame;
	}
	/**
	 * Sets id.
	 * @param id the id to set.
	 */
	public void setId(Integer id) {
		this.id = id;
	}
	/**
	 * Sets images.
	 * @param images the images to set.
	 */
	public void setImages(Image[] images) {
		this.images = images;
	}
	/**
	 * Sets transitionId.
	 * @param transitionId the transitionId to set.
	 */
	public void setTransitionId(Integer transitionId) {
		this.transitionId = transitionId;
	}
	/**
	 * Sets type.
	 * @param type the type to set.
	 */
	public void setType(TileType type) {
		this.type = type;
	}
	/**
	 * Sets the type from a string version of the TileType Enum.
	 * @param type The type to set.
	 */
	public void setType(String type) {
		if (type == null) {
			this.type = TileType.IMPASSABLE;
		} else {
			this.type = TileType.valueOf(type.toUpperCase());
		}
	}
}
